package com.wbao.dianniu.ui;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.lhh.apst.library.CustomPagerSlidingTabStrip2;
import com.lhh.apst.library.ViewHolder;
import com.umeng.analytics.MobclickAgent;
import com.wbao.dianniu.R;
import com.wbao.dianniu.data.HeadInfoData;
import com.wbao.dianniu.im.FollowListActivity;
import com.wbao.dianniu.im.LoginSampleHelper;
import com.wbao.dianniu.listener.IAddFriendListener;
import com.wbao.dianniu.listener.IBlackAccountListener;
import com.wbao.dianniu.listener.IFollowListener;
import com.wbao.dianniu.listener.IFriendDelListener;
import com.wbao.dianniu.listener.IHeadInfoListener;
import com.wbao.dianniu.listener.IShildAccountListener;
import com.wbao.dianniu.logical.Const;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.logical.GlobalUserData;
import com.wbao.dianniu.manager.AddFriendManger;
import com.wbao.dianniu.manager.BlackAccountManager;
import com.wbao.dianniu.manager.FollowManager;
import com.wbao.dianniu.manager.FriendDelManager;
import com.wbao.dianniu.manager.HeadInfoManager;
import com.wbao.dianniu.manager.ModifyRemarkHelper;
import com.wbao.dianniu.manager.ModifyRemarkHelper.IRemarkChanged;
import com.wbao.dianniu.update.ShareSDKManager;
import com.wbao.dianniu.manager.ShildAccountManager;
import com.wbao.dianniu.tabstrip.fragments.APSTSViewPager;
import com.wbao.dianniu.update.ErrorDialogHelper;
import com.wbao.dianniu.utils.BlurBitmapUtil;
import com.wbao.dianniu.utils.Notification;
import com.wbao.dianniu.utils.PictureDownloadUtils;
import com.wbao.dianniu.utils.ReportType;
import com.wbao.dianniu.utils.Utils;

import java.util.ArrayList;

import qiu.niorgai.StatusBarCompat;

/**
 * 个人信息
 *
 * @author yejianjun
 */
public class HeadInfoActivity extends FragmentActivity implements OnClickListener, IHeadInfoListener, IAddFriendListener,
        IFollowListener, IBlackAccountListener, IShildAccountListener, IRemarkChanged, IFriendDelListener, ViewPager.OnPageChangeListener {
    public static final String INTENT_FRIENDID = "com.intent.friendId";

    private LinearLayout waittingLayout;
    private ProgressBar waittingProBar;
    private TextView waittingTV;
    private ImageButton rightBtn;
    private ImageButton backBtn;
    private int friendId;
    private ImageView headPic;
    private TextView nameTV;
    private TextView labelTV;
    private TextView signatureTV;
    private Button followBtn;
    private Button addButton;
    private HeadInfoManager manager;
    private HeadInfoData resultData = new HeadInfoData();
    private AddFriendManger addFriendManager;
    private Dialog dialog;
    private Dialog deleteDialog;
    private int ShildStatus = 0;
    private ImageView sexIV;
    private ImageView addV;
    private String headUrl;
    private TextView tv_follow, tv_fans;
    private LinearLayout ll_follow, ll_fans;
    private View statusBarView;
    private LinearLayout statusBarLayout;

    public CustomPagerSlidingTabStrip2 mAPSTS;
    public APSTSViewPager mVP;
    private static final int VIEW_FIRST = 0;
    private static final int VIEW_SECOND = 1;
    private static final int VIEW_THREE = 2;
    private static final int VIEW_SIZE = 3;
    private SendQaFragment sendQaFragment;
    private HeadActFragment headActFragment;
    private HeadKnowFragment headKnowFragment;
    private FollowManager followManager;
    private ShildAccountManager shildManager;
    private BlackAccountManager blackManager;
    private FriendDelManager friendDelManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_head_info);
        StatusBarCompat.translucentStatusBar(this);

        initWattingView();

        backBtn = (ImageButton) findViewById(R.id.head_info_back);
        backBtn.setOnClickListener(this);
        initSandian();
        initBaseView();

        Intent intent = getIntent();
        String id = intent.getStringExtra(Const.INTENT_SCHEME_ID);
        if (null != id) {
            friendId = Integer.valueOf(id);
        } else {
            friendId = intent.getIntExtra(INTENT_FRIENDID, 0);
        }
        requestData(GlobalContext.getAccountId(), friendId);
        ModifyRemarkHelper.getInstance().addListener(this);

        setStatusBarView();
        initAPST();
    }

    private void initAPST() {
        mAPSTS = (CustomPagerSlidingTabStrip2) findViewById(R.id.head_info_tab);
        mVP = (APSTSViewPager) findViewById(R.id.head_info_apsts);
        mVP.setOffscreenPageLimit(VIEW_SIZE);

        FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
        mVP.setAdapter(adapter);
        adapter.notifyDataSetChanged();
        mAPSTS.setIndicatorHeight(4);
        mAPSTS.setViewPager(mVP);
        mAPSTS.setOnPageChangeListener(this);
    }

    private void setStatusBarView() {
        statusBarView = (View) findViewById(R.id.status_bar_view);
        int height = getStatusHeight();
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
        statusBarView.setLayoutParams(lp);
    }

    /**
     * 获取状态栏高度——方法1
     */
    private int getStatusHeight() {
        statusBarLayout = (LinearLayout) findViewById(R.id.head_info_statusbar_layout);
        //拿到初始图
        Bitmap initBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.user_bg);
        //处理得到模糊效果的图
        Bitmap blurBitmap = BlurBitmapUtil.blurBitmap(this, initBitmap, 20f);
        statusBarLayout.setBackgroundDrawable(new BitmapDrawable(blurBitmap));

        int statusBarHeight1 = -1;
        //获取status_bar_height资源的ID
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            statusBarHeight1 = getResources().getDimensionPixelSize(resourceId);
        }
        return statusBarHeight1;
    }

    private void initWattingView() {
        waittingLayout = (LinearLayout) findViewById(R.id.waitting_layout);
        waittingProBar = (ProgressBar) findViewById(R.id.waitting_progress);
        waittingTV = (TextView) findViewById(R.id.waitting_text_desc);
    }

    private void initSandian() {
        rightBtn = (ImageButton) findViewById(R.id.head_info_sandian);
        rightBtn.setVisibility(View.INVISIBLE);
        rightBtn.setImageResource(R.drawable.sandian);
        rightBtn.setOnClickListener(this);
    }

    private void initBaseView() {
        headPic = (ImageView) findViewById(R.id.head_info_image);
        nameTV = (TextView) findViewById(R.id.head_info_name);
        sexIV = (ImageView) findViewById(R.id.head_info_sex);
        addV = (ImageView) findViewById(R.id.head_add_v_iv);
        labelTV = (TextView) findViewById(R.id.head_info_label);
        signatureTV = (TextView) findViewById(R.id.head_info_signature);
        followBtn = (Button) findViewById(R.id.head_info_follow);
        addButton = (Button) findViewById(R.id.head_info_addFriend);
        tv_follow = (TextView) findViewById(R.id.head_follow);
        tv_fans = (TextView) findViewById(R.id.head_fans);
        ll_follow = (LinearLayout) findViewById(R.id.head_layout_follow);
        ll_fans = (LinearLayout) findViewById(R.id.head_layout_fans);

        headPic.setOnClickListener(this);
        followBtn.setOnClickListener(this);
        addButton.setOnClickListener(this);
        ll_follow.setOnClickListener(this);
        ll_fans.setOnClickListener(this);
    }

    // 请求数据
    private void requestData(int accountId, int friendAccountId) {
        manager = new HeadInfoManager(this);
        manager.addHeadListener(this);
        manager.headinfo(accountId, friendAccountId);
    }

    private void requestAddFriend(int accountId, int friendAccountId) {
        addFriendManager = new AddFriendManger(this);
        addFriendManager.addFriendListener(this);
        addFriendManager.addFriend(accountId, friendAccountId);
    }

    /**
     * @param accountId       用户ID
     * @param followAccountId 关注的用户ID
     */
    private void requestFollow(int accountId, int followAccountId) {
        followManager = new FollowManager(this);
        followManager.addFollowListener(this);
        followManager.follow(accountId, followAccountId);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ModifyRemarkHelper.getInstance().removeListener(this);
        if (null != dialog && dialog.isShowing()) {
            dialog.dismiss();
        }
        if (null != deleteDialog && deleteDialog.isShowing()) {
            deleteDialog.dismiss();
        }
        if (null != manager) {
            manager.removeHeadListener(this);
        }
        if (null != addFriendManager) {
            addFriendManager.removeAddFriendListener(this);
        }
        if (null != followManager) {
            followManager.removeFollowListener(this);
        }
        if (null != shildManager) {
            shildManager.removeShildAccountListener(this);
        }
        if (null != blackManager) {
            blackManager.removeBlackAccountListener(this);
        }
        if (null != friendDelManager) {
            friendDelManager.removeFriendDelListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.head_info_image:
                /** 点击放大图片 */
//			Intent intent = new Intent();
//			intent.putExtra(GlobalContext.BUNDLE_HEADPIC, headUrl);
//			intent.setClass(this, HeadInfoViewActivity.class);
//			this.startActivity(intent);
                ArrayList<String> urls2 = new ArrayList<>();
                urls2.add(GlobalContext.cdndownUrl + headUrl);
                Utils.imageBrower(HeadInfoActivity.this, 0, urls2);
                break;
            case R.id.head_info_back:
                finish();
                break;
            case R.id.head_info_follow:    //关注/取消关注
                if (friendId == GlobalContext.getAccountId()) {
                    Notification.toast(this, "不能关注自己");
                    return;
                }
                if (!GlobalContext.getPerfectData()) {
                    ErrorDialogHelper.getInstance().showPerfectAuth(this);
                    return;
                }
                if (1 == resultData.getIsFollow()) {
                    followBtn.setText("关注");
                    resultData.setIsFollow(0);
                } else {
                    followBtn.setText("取消关注");
                    resultData.setIsFollow(1);
                }
                requestFollow(GlobalContext.getAccountId(), resultData.getId());
                break;
            case R.id.head_info_addFriend:    //加好友/私聊
                if (friendId == GlobalContext.getAccountId()) {
                    Notification.toast(this, "不能加自己为好友");
                    return;
                }
                if (1 == resultData.getIsFriend()) {
                    //跳转到聊天界面
                    String appkey = getResources().getString(R.string.app_key);
                    GlobalUserData userData = new GlobalUserData();
                    LoginSampleHelper.getInstance().openChat(this, userData.getEnvironemt() + String.valueOf(resultData.getId()), appkey);
                } else if (0 == resultData.getIsFriend()) {
                    //加好友 私聊跳转
                    if (2 == resultData.getFriendStatus()) {
                        //跳转到聊天界面
                        String appkey = getResources().getString(R.string.app_key);
                        GlobalUserData userData = new GlobalUserData();
                        LoginSampleHelper.getInstance().openChat(this, userData.getEnvironemt() + String.valueOf(resultData.getId()), appkey);
                    } else if (0 == resultData.getFriendStatus() || (3 == resultData.getFriendStatus()) || (4 == resultData.getFriendStatus())) {
                        //不是好友，判断是否可以加好友
                        if (1 == resultData.getBeFriend()) {
                            Notification.toast(this, "该用户不允许加好友");
                            return;
                        } else {
                            if (!GlobalContext.getPerfectData()) {
                                ErrorDialogHelper.getInstance().showPerfectAuth(this);
                            } else {
                                requestAddFriend(GlobalContext.getAccountId(), resultData.getId());
                            }
                        }
                    } else if (1 == resultData.getFriendStatus()) {
                    }
                }
                break;
            case R.id.head_info_sandian:    // 右三点
                //点击三点 弹出对话框
                showDialog();
                break;
            case R.id.head_layout_follow:
                Intent intent = new Intent();
                intent.putExtra(Const.INTENT_TITLE, getResources().getString(R.string.follow));
                intent.putExtra(Const.INTENT_ID, friendId);
                intent.setClass(HeadInfoActivity.this, FollowListActivity.class);
                startActivity(intent);
                break;
            case R.id.head_layout_fans: // 粉丝
                Intent fansIntent = new Intent();
                fansIntent.putExtra(Const.INTENT_ID, friendId);
                fansIntent.setClass(HeadInfoActivity.this, FansListActivity.class);
                startActivity(fansIntent);
                break;
            default:
                break;
        }
    }

    /**
     * 显示认证弹出框
     */
    private void showDialog() {
        dialog = new Dialog(this, R.style.my_dialog);
//        Window win = dialog.getWindow();
//        win.getDecorView().setPadding(3, 3, 3, 3);
//        win.setGravity(Gravity.BOTTOM);
        View view = LayoutInflater.from(this).inflate(R.layout.bottom_dialog, null);
        Button btn_share = (Button) view.findViewById(R.id.bottom_share);
        Button btn_shield = (Button) view.findViewById(R.id.bottom_pb);
        Button btn_black = (Button) view.findViewById(R.id.bottom_lh);
        Button btn_report = (Button) view.findViewById(R.id.bottom_jb);
        Button btn_cancel = (Button) view.findViewById(R.id.bottom_cancel);
        Button modifyBtn = (Button) view.findViewById(R.id.modify_beizu);
        Button deleteBtn = (Button) view.findViewById(R.id.delete_account);
        // 不是好友隐藏修改备注和删除好友
        if (1 != resultData.getIsFriend()) {
            modifyBtn.setVisibility(View.GONE);
            deleteBtn.setVisibility(View.GONE);
        }
        btn_black.setText("拉黑");
        if (1 == ShildStatus) {
            btn_shield.setText("已屏蔽");
        } else {
            btn_shield.setText("屏蔽");
        }

        Window win = dialog.getWindow();
        win.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.x = 0;
        lp.y = 0;
        lp.width = (int) getResources().getDisplayMetrics().widthPixels; // 宽度
        view.measure(0, 0);
        lp.height = view.getMeasuredHeight();
        lp.alpha = 9f; // 透明度
        win.setAttributes(lp);

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        // 删除好友
        deleteBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                showDelete();
            }
        });
        // 分享
        btn_share.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
                // 获取某个用户的头像
                String content = "昵称：" + resultData.getRealName() + "\n" + "标签：" + resultData.getLabel();
                //调用分享模块
                ShareSDKManager shareSDKManager = ShareSDKManager.getInstance();
                shareSDKManager.showShare(HeadInfoActivity.this, content, 2, GlobalContext.cdndownUrl + headUrl, friendId);
            }
        });

        //修改备注
        modifyBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
                Intent modifyIntent = new Intent();
                modifyIntent.putExtra(Const.BUNDLE_ACCOUNTID, friendId);
                String remarkName = resultData.getFriendRemarkName();
                if (TextUtils.isEmpty(remarkName)) {
                    remarkName = resultData.getRealName();
                }
                modifyIntent.putExtra(Const.BUNDLE_REALNAME, remarkName);
                modifyIntent.setClass(HeadInfoActivity.this, ModifyRemarkActivity.class);
                startActivity(modifyIntent);
            }
        });

        // 屏蔽
        btn_shield.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
                //屏蔽
                shildManager = new ShildAccountManager(HeadInfoActivity.this);
                shildManager.addShildAccountListener(HeadInfoActivity.this);
                shildManager.shildAccount(GlobalContext.getAccountId(), friendId);
            }
        });
        // 拉黑
        btn_black.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
                blackManager = new BlackAccountManager(HeadInfoActivity.this);
                blackManager.addBlackAccountListener(HeadInfoActivity.this);
                blackManager.blackAccount(GlobalContext.getAccountId(), friendId);
            }
        });
        // 举报
        btn_report.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
                if (friendId == GlobalContext.getAccountId()) {
                    Notification.toast(HeadInfoActivity.this, "自己不能举报自己");
                    return;
                }
                Utils.intoReportActivity(HeadInfoActivity.this, ReportType.TYPE_USER, friendId);
            }
        });
        btn_cancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        });
        dialog.setContentView(view);
        dialog.show();
    }

    private void showDelete() {
        deleteDialog = new Dialog(this, R.style.custom_Dialog);
        Window win = deleteDialog.getWindow();
        win.getDecorView().setPadding(3, 3, 3, 3);
        win.setGravity(Gravity.CENTER);
        View view = LayoutInflater.from(this).inflate(R.layout.custom_message_dialog, null);
        Button okBtn = (Button) view.findViewById(R.id.custom_msg_ok);
        Button cancelBtn = (Button) view.findViewById(R.id.custom_msg_cancel);
        TextView message = (TextView) view
                .findViewById(R.id.custom_msg_message);
        message.setText("确认删除好友吗");
        deleteDialog.setContentView(view);
        deleteDialog.setCancelable(true);
        deleteDialog.show();
        okBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (null != deleteDialog && deleteDialog.isShowing()) {
                    deleteDialog.dismiss();
                }
                friendDelManager = new FriendDelManager(HeadInfoActivity.this);
                friendDelManager.addFriendDelListener(HeadInfoActivity.this);
                friendDelManager.friendDel(GlobalContext.getAccountId(), friendId);
            }
        });
        cancelBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != deleteDialog && deleteDialog.isShowing()) {
                    deleteDialog.dismiss();
                }
            }
        });
    }

    @Override
    public void onHeadFailure(int errorCode, String errorMsg) {
        waittingLayout.setVisibility(View.VISIBLE);
        waittingProBar.setVisibility(View.GONE);
        waittingTV.setText("加载失败，请稍后再试...");
//		ErrorMsgHandler.getInstance().onErrorMsg(this, errorCode, errorMsg);
    }

    @Override
    public void onHeadSuccess(HeadInfoData data) {
        waittingLayout.setVisibility(View.GONE);
        rightBtn.setVisibility(View.VISIBLE);
        //收到数据 显示
        if (null != data) {
            resultData = data;
            headUrl = data.getHeadPic();
            PictureDownloadUtils.displayHeadImage(this, headPic, data.getHeadPic());
            String name = data.getFriendRemarkName();
            if (!TextUtils.isEmpty(name)) {
                name = data.getRealName() + "(" + name + ")";
            } else {
                name = data.getRealName();
            }
            nameTV.setText(name == null ? "" : name);
            labelTV.setText(data.getLabel() == null ? "" : data.getLabel());
            signatureTV.setText(data.getDescribe() == null ? "简介：" : "简介：" + data.getDescribe());
            Utils.showSex(this, data.getSex(), sexIV);
           /* if (1 == data.getSex()) {
                sexIV.setImageResource(R.drawable.boy_icon);
            } else {
                sexIV.setImageResource(R.drawable.girl_icon);
            }*/
            if (data.getIsIndustryAuthority()) {
                addV.setVisibility(View.VISIBLE);
            } else {
                addV.setVisibility(View.GONE);
            }
            if (1 == data.getIsFriend()) {
                addButton.setText("私聊");
                addButton.setClickable(true);
            } else if (0 == data.getIsFriend()) {
                if (2 == data.getFriendStatus()) {
                    addButton.setText("私聊");
                    addButton.setClickable(true);
                } else if (0 == data.getFriendStatus() || 3 == data.getFriendStatus() || 4 == data.getFriendStatus()) {
                    addButton.setText("+好友");
                    addButton.setClickable(true);
                } else if (1 == data.getFriendStatus()) {
                    addButton.setText("已申请");
//                    addButton.setBackgroundColor(getResources().getColor(R.color.remark_gray_bg));
                    addButton.setClickable(false);
                }
            }

            if (1 == data.getIsFollow()) {
                followBtn.setText("取消关注");
            } else {
                followBtn.setText("关注");
            }
            tv_follow.setText(data.getFollowCount() + "");
            tv_fans.setText(data.getFansCount() + "");
        }

    }

    @Override
    public void onAddFriendFailure(int errorCode, String errorMsg) {
    }

    @Override
    public void onAddFriendSuccess() {
        Notification.toast(this, "请求已发送");
        addButton.setText(getResources().getString(R.string.already_applay));
//        addButton.setBackgroundColor(getResources().getColor(R.color.remark_gray_bg));
        addButton.setClickable(false);
//		resultData.setIsFriend(1);
        resultData.setFriendStatus(1);
    }

    @Override
    public void onFollowFailure(int errorCode, String errorMsg) {
    }

    @Override
    public void onFollowSuccess() {
    }

    @Override
    public void onBlackAccountFailure(int errorCode, String errorMsg) {
    }

    @Override
    public void onBlackAccountSuccess() {
        Notification.toast(this, "拉黑成功");
    }

    @Override
    public void onShildAccountFailure(int errorCode, String errorMsg) {
    }

    @Override
    public void onShildAccountSuccess() {
        if (0 == ShildStatus) {
            ShildStatus = 1;
            Notification.toast(this, "已屏蔽");
        } else {
            ShildStatus = 0;
            Notification.toast(this, "已取消");
        }
    }

    @Override
    public void remarkChanged(String remark) {
        nameTV.setText(resultData.getRealName() + "(" + remark + ")");
    }

    @Override
    public void onFriendDelFailure(int errorCode, String errorMsg) {
        Notification.toast(this, errorMsg);
    }

    @Override
    public void onFriendDelSuccess() {
        Notification.toast(this, "删除成功");
        finish();
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    private class FragmentAdapter extends FragmentStatePagerAdapter implements
            CustomPagerSlidingTabStrip2.CustomTabProvider {
        protected LayoutInflater mInflater;

        public FragmentAdapter(FragmentManager fm) {
            super(fm);
            mInflater = LayoutInflater.from(HeadInfoActivity.this);
        }

        @Override
        public Fragment getItem(int position) {
            // TODO Auto-generated method stub
            if (position >= 0 && position < VIEW_SIZE) {
                switch (position) {
                    case VIEW_FIRST:
                        if (null == sendQaFragment)
                            sendQaFragment = SendQaFragment.instance(HeadInfoActivity.this, SendQaFragment.TYPE_ALL, friendId);
                        return sendQaFragment;
                    case VIEW_SECOND:
                        if (null == headActFragment)
                            headActFragment = HeadActFragment.instance(HeadInfoActivity.this, friendId);
                        return headActFragment;
                    case VIEW_THREE:
                        if (null == headKnowFragment)
                            headKnowFragment = HeadKnowFragment.instance(HeadInfoActivity.this, friendId);
                        return headKnowFragment;
                    default:
                        break;
                }
            }

            return null;
        }

        @Override
        public int getCount() {
            return VIEW_SIZE;
        }

        @Override
        public View getSelectTabView(int position, View convertView) {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.custom_select_tab, null);
            }
            TextView tv = ViewHolder.get(convertView, R.id.tvTab);
            tv.setText(getPageTitle(position));
            tv.setTextColor(getResources().getColor(R.color.blue_text));
            return convertView;
        }

        @Override
        public View getDisSelectTabView(int position, View convertView) {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.custom_disselect_tab, null);
            }
            TextView tv = ViewHolder.get(convertView, R.id.tvTab);
            tv.setText(getPageTitle(position));
            tv.setTextColor(getResources().getColor(R.color.gray_text));
            return convertView;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case VIEW_FIRST:
                    return getResources().getString(R.string.qa_title);
                case VIEW_SECOND:
                    return getResources().getString(R.string.act_title);
                case VIEW_THREE:
                    return getResources().getString(R.string.knowledge);
                default:
                    break;
            }

            return super.getPageTitle(position);
        }

    }


}
